<template>
    <div class="success">
      <img :src="require(`../../../public/img/email/${isTime?'successTime':'mailSuccess'}.png`)" alt="">
      <p>邮件已为您保存至
        <span v-if="!isTime" @click="move('/mail/send/index')">[已发送]</span>
        <span v-else @click="move('/mail/draft/index')">[草稿箱]</span>
      </p>
      <div class="btn">
        <el-button type="primary" @click="toDetail" v-show="!parseInt(result.monocular)"><i class="icon-review"></i> 查看此件</el-button>
        <el-button type="primary" @click="move('/mail/write/index')"><i class="el-icon-edit"></i> 继续写信</el-button>
      </div>
    </div>
</template>

<script>
    import {getDiffList} from '@/util/util'
    export default {
        name: "success",
        data(){
          return{
              isTime: false,
              result:{}
          }
        },
        mounted(){
            this.result = JSON.parse(this.$route.query.params);
            this.isTime=this.result.emailSendTiming!='';
        },
        methods:{
            toDetail(){
                if (this.isTime) {//定时发送
                    sessionStorage.setItem("lastpath", '/mail/draft/index')
                    this.$store.commit('SET_ISFRAG', 2)
                    this.$router.push({
                        path: '/mail/edit',
                        query: {
                            id: this.result.id
                        }
                    })
                } else {//普通 - 已发送详情
                    const ID = this.result.id.toString();
                    if (getDiffList(ID, 'emailListOutTab') == -1) {
                        this.$store.commit('SET_EMAILLISTOUTTAB', {
                            type: 1, row: {
                                id: ID,
                                title: this.result.title,
                                state: 1,
                                close: true
                            }
                        })
                    } else {
                        this.$store.commit('SET_EMAILLISTOUTTAB', {type: 0, current: ID})
                    }
                    this.$store.commit('SET_ISFRAG', 3)
                    if(this.target != 'SET_EMAILLISTOUTTAB'){//收件箱 - 未读箱 - 待处理 - 需要跳转
                        this.$router.push({
                            path: '/mail/send/index'
                        })
                    }
                }
            },
            move(path) {
                if (path == '/mail/send/index') {
                    this.$store.commit('SET_ISFRAG', 3)
                } else if(path=='/mail/draft/index') {
                    this.$store.commit('SET_ISFRAG', 2)
                }
                this.$router.push(path);
            }
        }
    }
</script>

<style scoped lang="scss">
  .success {
    text-align: center;
    margin-top: 170px;
    p{
      line-height: 34px;
      border-radius: 10px;
      color: #232323;
      margin: 20px auto !important;
      width: 322px;
      background-color: #E9F3FD;
      span{
        color: #2A97F9;
        cursor: pointer;
      }
    }
    .btn{
      button{
        width:129px;
        text-align: center;
        height: 34px;
        line-height:34px;
        background:rgba(42,151,249,1);
        border-radius:10px;
        font-size: 14px;
        padding: 0;
      }
    }
  }
</style>
